{include file="public_head" /}
<!-- upload -->
<link href="__STATIC__/css/uploads.css" rel="stylesheet">
<!-- Select2 -->
<link href="__STATIC__/css/select/select2.min.css" rel="stylesheet">


<body class="nav-md">

<div class="container body">

    <div class="main_container">

        {include file="public_sidebar,public_nav" /}
        <!-- page content -->
        <div class="right_col" role="main">
            <div class="">

                <div class="page-title">
                    <!--<div class="title_left">-->
                    <!--<h3>广告位管理</h3>-->
                    <!--</div>-->
                </div>
                <div class="clearfix"></div>
                <div class="row">
                    <div class="col-md-12 col-sm-12 col-xs-12">
                        <div class="x_panel">
                            <div class="x_title">
                                <h2>礼包会员卡
                                    <!--<small>different form elements</small>-->
                                </h2>
                                <ul class="nav navbar-right panel_toolbox">
                                    <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                                    </li>
                                    <li><a class="close-link"><i class="fa fa-close"></i></a>
                                    </li>
                                </ul>
                                <div class="clearfix"></div>
                            </div>
                            <script>
                                function CheckAll(val) {
                                    $("input[name='abc[]']").each(function () {
                                        this.checked = val;
                                    });
                                }
                            </script>
                            <div class="x_content">
                                <br/>
                                <div style="width: 100%" class="form-group">
                                <input style="margin-left:10px;" type="checkbox" class="checkall"
                                       onclick="CheckAll(this.checked);"/>
                                </div>
                                <form class="form-horizontal" enctype="multipart/form-data" action="{:url('gift_card')}?abc=43" method="post" id="registerForm">
                                    {volist name="$zcs" key="k" id="vo"}


                                            <div style="width: 100%" class="form-group">
                                                <div  style="width: 40px;" class="col-md-1 col-sm-6 col-xs-12" >
                                                   <input id="a{$k}" type="checkbox" name="abc[]" value="{$k}"/>
                                                </div>
                                                <div class="col-md-2 col-sm-6 col-xs-12" >

                                                    <input style="width: 100%" type="text" placeholder="实体卡卡号"
                                                           class="form-control col-md-7 col-xs-12" name="card_num[{$k}]"
                                                           value="{php}if(!empty($gift_card[$k-1]['card_num'])){ echo  $gift_card[$k-1]['card_num'];}else{echo  '';}{/php}" nullmsg="实体卡卡号不能为空"  errormsg="实体卡卡号"
                                                    >
                                                </div>

                                                <div class="col-md-2 col-sm-6 col-xs-12" >
                                                    {php}
                                                    if(!empty($gift_card[$k-1]['card_password'])){
                                                    $card_password =  $gift_card[$k-1]['card_password'];
                                                    }else{
                                                    $card_password =  '';
                                                    }
                                                    {/php}

                                                    {if condition="session('role_id') neq 1 && !empty($card_password) "}

                                                    <input style="width: 100%" type="text" placeholder="激活码"
                                                           class="form-control col-md-7 col-xs-12" name="card_password[{$k}]"
                                                           value="{:hideStr($card_password,0,14);}"  nullmsg="激活码不能为空"  errormsg="激活码"
                                                    >

                                                    {else/}
                                                    <input style="width: 100%" type="text" placeholder="激活码"
                                                           class="form-control col-md-7 col-xs-12" name="card_password[{$k}]"
                                                           value="{$card_password}" nullmsg="激活码不能为空"  errormsg="激活码"
                                                    >
                                                    {/if}

                                                </div>
                                                <div class="col-md-2 col-sm-6 col-xs-12">
                                                    <select idd="{$k}" onchange="changeyewuyuan(this,this.value,{$k})" name="yewuyuan_id[{$k}]" class="select2_single"
                                                            style="width:100%;" tabindex="-1"
                                                            datatype="*"

                                                    >
                                                        <option value="0">无</option>
                                                        {volist name="single_list" id="item"}
                                                        <option value="{$item.id}"
                                                                {php}if(!empty($gift_card[$k-1]['yewuyuan_id'])){ $yewuyuan_id = $gift_card[$k-1]['yewuyuan_id'];}else{ $yewuyuan_id =  '';}{/php}
                                                        {eq name="$item.id" value="$yewuyuan_id"}selected{/eq}>
                                                        {neq name="$item.level" value="1"}{:str_repeat('&nbsp&nbsp',$item.level)}{/neq}|{:str_repeat('--',$item.level)}{$item.nickname}
                                                        </option>
                                                        {/volist}
                                                    </select>
                                                </div>
                                                {php}if(!empty($gift_card[$k-1]['status'])){ $status = $gift_card[$k-1]['status'];}else{ $status =  '1';}{/php}
                                                <div class="col-md-3 col-sm-6 col-xs-12">
                                                    <label class="radio_box">
                                                        <input {eq name="$status" value="2"}disabled{/eq} type="radio" name="status{$k}[]" id="status_{$k}" class="cartradio"
                                                               value="1"
                                                               datatype="*"
                                                               nullmsg="请选择会员卡类型！" errormsg="请选择会员卡类型！"
                                                               {eq name="$status" value='1' }
                                                               checked
                                                               {/eq}
                                                        >&nbsp;&nbsp;
                                                        <label for="status_{$k}"></label>
                                                        <span>未激活</span>
                                                        &nbsp;&nbsp;
                                                    </label>
                                                    <label class="radio_box">

                                                        <input disabled  type="radio" name="status{$k}[]" id="status_{$k}_b" class="cartradio"
                                                               value="2"
                                                               datatype="*"
                                                               nullmsg="请选择会员卡类型！" errormsg="请选择会员卡类型！"
                                                               {eq name="$status" value='2' }
                                                               checked
                                                               {/eq}
                                                        >&nbsp;&nbsp;
                                                        <label for="status_{$k}_b"></label>
                                                        <span>已激活</span>
                                                        &nbsp;&nbsp;

                                                    </label>
                                                    <label class="radio_box">
                                                        <input {eq name="$status" value="2"}disabled{/eq} type="radio" name="status{$k}[]" id="status_{$k}_c" class="cartradio"
                                                               value="3"
                                                               datatype="*"
                                                               nullmsg="请选择会员卡类型！" errormsg="请选择会员卡类型！"
                                                               {eq name="$status" value='3' }
                                                               checked
                                                               {/eq}
                                                        >&nbsp;&nbsp;
                                                        <label for="status_{$k}_c"></label>
                                                        <span>禁止激活</span>
                                                        &nbsp;&nbsp;
                                                    </label>
                                                </div>
                                            </div>

                                    <input type="hidden" name="order_number[{$k}]" value="{php}if(!empty($gift_card[$k-1]['order_number'])){ echo $gift_card[$k-1]['order_number'];}else{echo '';}{/php}">
                                    <input type="hidden" name="order_id[{$k}]" value="{php}if(!empty($gift_card[$k-1]['order_id'])){ echo $gift_card[$k-1]['order_id'];}else{echo '';}{/php}">
                                    <input type="hidden" name="jihuo_time[{$k}]" value="{php}if(!empty($gift_card[$k-1]['jihuo_time'])){ echo $gift_card[$k-1]['jihuo_time'];}else{echo '';}{/php}">
                                    <input name="gift_id" value="{:input('gift_id')}" type="hidden" />
                                    <input name="zcs" value="{:input('zcs')}" type="hidden" />
                                    <input name="pages" value="{:input('pages')}" type="hidden" />

                                    {/volist}

                                    <ul class="pagination">
                                    {for start="1" end="$paga_a+1"}
                                    <li><a {eq name="$i" value=":input('pages')"}class="active"{/eq} href="{:url('gift_card',['gift_id' => input('gift_id'),'zcs' => input('zcs')])}?pages={$i}">{$i}</a></li>
                                    {/for}
                                    </ul>
                                    <style>
                                        .active{ font-weight: bold}
                                    </style>

                    <script>
                        function a() {

                        }
                        function changeyewuyuan(t,v,k) {
                            var a = $("#a"+k).is(':checked');
                            console.log(k);
                            console.log(a);
                            if(a){
                                var csj_data;
                                $.ajax({
                                    url:"{:url('gift2/salesman')}",
                                    dataType:'html',
                                    type:'post',
                                    async: false,
                                    data:{'yewuyuan_id':v,k:k},
                                    success:function(ret){
                                        csj_data = ret;


                                    }
                                });

                                console.log(csj_data);
                                $('input[name="abc[]"]:checked').each(function(){
                                    //console.log($(this).val());
                                    var id = $(this).val();

                                    console.log(id);
                                    //  $(t).removeAttr('checked');
                                    var checked_id = this.checked;

                                    $('#id'+k).parent().remove();

                                    //$(this).parent().next().next().next().html(csj_data);
                                    var  str = '<select idd="{$k}" onchange="changeyewuyuan(this,this.value,'+id+')" name="yewuyuan_id['+id+']" class="select2_single"\n' +
                                        '                                                            style="width:100%;" tabindex="-1"\n' +
                                        '                                                            datatype="*"\n' +
                                        '\n' +
                                        '                 ' +
                                        '                                   >';
                                    str += csj_data;
                                    str += '</select>';
                                    str += '<script src="__STATIC__\/js\/select\/select2.full.min.js"><\/script>';
                                    str +="<script>\n" +
                                        "                                        $(\".select2_single\").select2({\n" +
                                        "                                            placeholder: \"请选择分类\",\n" +
                                        "                                            allowClear: true\n" +
                                        "                                        });\n" +
                                        "                                    <\/script>";
                                    console.log(str);
                                    $(this).parent().next().next().next().html(str);

                                });
                            }



                        }

                    </script>

                                    <div style="width: 100%" class="form-group">
                                        <input style="margin-left:10px;" type="checkbox" class="checkall"
                                               onclick="CheckAll(this.checked);"/>
                                    </div>
                                    <div class="form-group">

                                        <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">


                                            {if condition="session('role_id') neq 1 && empty($card_password) "}
                                            <button type="submit" class="btn btn-primary">提交</button>
                                            {/if}
                                            {if condition="session('role_id') eq 1 "}
                                            <button type="submit" class="btn btn-primary">提交</button>
                                            {/if}
                                            <a type="reset" class="btn btn-success" href="{:url('gift2/index')}">返回</a>
                                        </div>
                                    </div>

                                </form>

                            </div>
                        </div>
                    </div>
                </div>


            </div>
            <!-- /page content -->

        </div>

    </div>
</div>

{include file="public_foot" /}

<!-- Datatables-->
<script src="__STATIC__/js/datatables/jquery.dataTables.min.js"></script>
<script src="__STATIC__/js/datatables/dataTables.bootstrap.js"></script>
<!-- validform -->
<script src="__STATIC__/js/Validform_v5.3.2_min.js"></script>
<script src="__STATIC__/js/layer.js"></script>
<!--select-->
<script src="__STATIC__/js/select/select2.full.min.js"></script>
<!--upload-->
<script type="text/javascript" src="__STATIC__/js/uploadPreview.js"></script>

<!-- ueditor -->
<script type="text/javascript" charset="utf-8" src="__STATIC__/editor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__STATIC__/editor/ueditor.all.min.js"></script>
<script type="text/javascript" charset="utf-8" src="__STATIC__/editor/lang/zh-cn/zh-cn.js"></script>
<style>
    .layui-layer-ico {
        background: url(/default/icon.png) no-repeat;
    }
</style>
<script>
    $('#parentIframe').click(function(){
        var title = $('[name="username"]').val();
        if(!title){
            layer.msg('用户名或车牌号不能为空');
            return;
        }
        layer.open({
            type: 2,
            area: ['700px', '450px'],
            fixed: false, //不固定
            maxmin: true,
            content: 'http://lihai.xmdonkey.com/index.php/console/member/title?title='+title
        });
    });
    //upload
    window.onload = function () {
        new uploadPreview({UpBtn: "up_img", DivShow: "imgdiv", ImgShow: "imgShow"});
    }
    $(".select2_single").select2({
        placeholder: "",
        allowClear: true
    });

    // 实例化编辑器
    var ue = UE.getEditor('containers');
    //validform
    $(function () {

        $.Tipmsg.r = null;

        var showmsg = function (msg) {
            //假定你的信息提示方法为showmsg， 在方法里可以接收参数msg，当然也可以接收到o及cssctl;
            alert(msg);
        }
        $("#registerForm").Validform({
            tiptype: function (msg) {
                layer.msg(msg);
            },
            tipSweep: true
        });


        // select2


        $(".select2_multiple").select2({
            maximumSelectionLength: 0,
            placeholder: "请选择关联品牌",
            allowClear: true
        });

    })


</script>
</body>

</html>
